import java.util.Locale;

class Student{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Text {

    public static void main(String[] args) {
        StringBuffer stringBuffer=new StringBuffer();
        String s="abcdef";
        System.out.println(s.contains("hc"));
        StringBuilder stringBuilder=new StringBuilder();
    }
    public static void main12(String[] args) {
        String s="  abc d e f g   ";
        System.out.println(s);
        String s2=s.trim();//只会去除 左右两边的空格
        System.out.println(s2);
    }
    public static void main11(String[] args) {
        String s1="abcdef";
        String s2=s1.substring(1);
        System.out.println(s2);
        String s3=s1.substring(2,4);//[)
        System.out.println(s3);
    }
    public static void main10(String[] args) {
        String s="name=zhangsan&age=10";
        String[] strings=s.split("&");
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }
        String[] strings1=s.split("=|&");
        for (int i = 0; i < strings1.length; i++) {
            System.out.println(strings1[i]);
        }
        String s1="aa\\bb\\cc";
        String[] strings2=s1.split("\\\\");
        for (int i = 0; i < strings2.length; i++) {
            System.out.println(strings2[i]);
        }
        String s2="192.11.106";
        String[] strings3=s2.split("\\.");
        for (int i = 0; i < strings3.length; i++) {
            System.out.println(strings3[i]);
        }
        String str = "hello world hello bit" ;
        String[] result = str.split(" ",2) ;
        for(String a: result) {
            System.out.println(a);
        }
    }
    public static void main9(String[] args) {
        String s="ababcabcd";
        String s1=s.replace('a','k');
        System.out.println(s1);
        s1=s.replace("ab","ppp");
        System.out.println(s1);
        s1=s.replaceFirst("ab","qq");
        System.out.println(s1);
        s1=s.replaceAll("ab","rrrr");
        System.out.println(s1);
    }
    public static void main8(String[] args) {
        //字符串转数组
        String s="hello";
        char[] array=s.toCharArray();
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
        //格式化输出
        String s1=String.format("%d-%d-%d",2024,05,29);
        System.out.println(s1);
    }
    public static void main7(String[] args) {
        //大小写转换
        String s1=new String("hello");
        String s2=s1.toUpperCase();//涉及String类型的转换 不是在原来本身进行修改 还是产生新对象
        System.out.println(s2);
        String s3="HELLO";
        System.out.println(s3.toLowerCase());
    }
    public static void main6(String[] args) {
        String s1=String.valueOf(1234);
        String s2=String.valueOf(12.34);
        String s3=String.valueOf(true);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s1+1);
        String s4=String.valueOf(new Student("zhangsan",10));
        System.out.println(s4);
        int data1=Integer.parseInt("1234");
        double data2=Double.parseDouble("12.34");
        System.out.println(data1+1);
        System.out.println(data2+0.1);
    }
    public static void main5(String[] args) {
        String s="ababcabcd";
        int index=s.lastIndexOf('a');//从后往前找
        System.out.println(index);
        index=s.lastIndexOf('a',4);
        System.out.println(index);
        index=s.lastIndexOf("ab");
        System.out.println(index);
        index=s.lastIndexOf("ab",4);
        System.out.println(index);
    }
    public static void main4(String[] args) {
        String s="helolo";

        int index=s.indexOf('l');
        System.out.println(index);
        index=s.indexOf('l',3);
        System.out.println(index);
        index=s.indexOf("lo");
        System.out.println(index);
        index=s.indexOf("lo",4);
        System.out.println(index);
        /*char ch=s.charAt(0);
        System.out.println(ch);*/
        /*for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            System.out.println(ch);
        }*/
    }
    public static void main3(String[] args) {
        String s1=new String("hello");
        String s2=new String("abcdef");
        System.out.println(s1.compareTo(s2));

        String s3=new String("abcdeF");
        //忽略大小写比较 compareToIgnoreCase
        System.out.println(s2.compareToIgnoreCase(s3));
    }
    public static void main2(String[] args) {
        String str1=new String("hello");
        String str2=new String("hello");
        String str3=str1;
        System.out.println(str3);
        System.out.println(str1);
        System.out.println(str1 == str2);
        System.out.println(str1 == str3);
        System.out.println(str2 == str3);
        System.out.println("===============");
        System.out.println(str1.equals(str3));
        System.out.println(str1.equals(str2));
        System.out.println(str2.equals(str3));
        System.out.println("===============");

    }
    public static void main1(String[] args) {
        String str1="hello";
        String str2=new String("world");
        char[] value={'a','b','c'};
        String str3=new String(value);
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
    }
}
